<?php
/*
 * author: wiloke && phan tien hien
 * author uri: wiloke.com
 * date: 05/01/2014
 * time: 12:40 PM
 */

// $aOurServices = isset($this->aOptions['theme_options']['ourservices']) && !empty($this->aOptions['theme_options']['ourservices']) ? $this->aOptions['theme_options']['ourservices'] : '';



$selected = ''; 

if ( isset($_POST) && !empty($_POST['wo-save-options']) )
{
    if ( !wp_verify_nonce($_POST["init-save-options"], "process-save-options") )
        die("Something go error");
    unset($_POST['_wp_http_referer']);
    unset($_POST['init-save-options']);
    unset($_POST['_wo_nonce']);
    unset($_POST['wo-save-options']);
    unset($_POST['data-import']);
    update_option("qva_save_theme_options", $_POST);
}

$aOptions = get_option("qva_save_theme_options");



$aOurServices   = isset($aOptions['theme_options']['ourservices']) ? $aOptions['theme_options']['ourservices'] : '';
$aAboutUs       =  isset($aOptions['theme_options']['aboutus']) && !empty($aOptions['theme_options']['aboutus']) ? $aOptions['theme_options']['aboutus'] : '';
$aOurteam       = isset($aOptions['theme_options']['ourteam']) && !empty($aOptions['theme_options']['ourteam']) ? $aOptions['theme_options']['ourteam'] : '';
$aOurWork       = isset($aOptions['theme_options']['ourwork']) && !empty($aOptions['theme_options']['ourwork']) ? $aOptions['theme_options']['ourwork'] : '';
$aOurClients    = isset($aOptions['theme_options']['ourclients']) && !empty($aOptions['theme_options']['ourclients']) ? $aOptions['theme_options']['ourclients'] : '';
$aContact       = isset($aOptions['theme_options']['contact']) && !empty($aOptions['theme_options']['contact']) ? $aOptions['theme_options']['contact'] : '';
$aFooter        = isset($aOptions['theme_options']['footer']) && !empty($aOptions['theme_options']['footer']) ? $aOptions['theme_options']['footer'] : '';
$aHeader        = isset($aOptions['theme_options']['header']) && !empty($aOptions['theme_options']['header']) ? $aOptions['theme_options']['header'] : '';
$aDesign        = isset($aOptions['theme_options']['design']) && !empty($aOptions['theme_options']['design']) ? $aOptions['theme_options']['design'] : '';
$aLogo          = isset($aOptions['theme_options']['logo'])  && !empty($aOptions['theme_options']['logo']) ? $aOptions['theme_options']['logo'] : '';
$aPageNotFound  = isset($aOptions['theme_options']['404'])  && !empty($aOptions['theme_options']['404']) ? $aOptions['theme_options']['404'] : '';
$aBlog          = isset($aOptions['theme_options']['blog'])  && !empty($aOptions['theme_options']['blog']) ? $aOptions['theme_options']['blog'] : '';
?>

<!-- <div id="qva-settings" class="alert alert-success" style="display:none">Successfully!</div> -->
<div id="qva-success" class="alert alert-success" style="display:none">Your data has been imported!</div>
<div id="qva-empty-data" class="alert alert-danger" style="display:none">Opp, You do not have data yet ;(</div>

<form action="" method="POST">

<?php  wp_nonce_field("process-save-options", "init-save-options"); ?>

<div id="main-tab" class="main-tab">

    <ul class="main-ui">
        <li><a href="#main-1">General</a></li>
        <li><a href="#main-2">Design</a></li>
        <li><a href="#main-3">Import-Export</a></li>
       
    </ul>



    <div id="main-1" class="main-tabs-panel">
        <div id="inner-tab" class="inner-tab">
            <div class="menu-left">
                <ul class="tab-left"> 
                    <li><a href="#basic"><i class="fa fa-wrench"></i>Basic</a></li>
                    <li><a href="#section"><i class="fa fa-laptop"></i>Section</a></li>
                    <li><a href="#footer"><i class="fa fa-cog"></i>Footer</a></li>
                    <li><a href="#pagenotfound"><i class="fa fa-file-archive-o"></i>404</a></li>
                </ul>
                <!-- <div class="wo-wrap-button">
                    <input class="button button-primary" type="submit" name="wo-save-options" value="Save">
                    <input class="button" type="submit" name="wo-reset-options" value="Reset">
                </div> -->
            </div>


            
            <div id="basic" class="inner-tabs-panel">
                <div class="inner-content">
                    <div class="container-12-fluid">
                        <div class="container-12-row">
                            <div class="large-12">
                                <!-- Panel -->
                                <div class="panel">

                                    <div class="panel-heading">
                                        <div class="panel-title">
                                           Logo
                                        </div>
                                    </div>

                                    <div class="panel-body">
                                        <label class="form-label">Logo Type</label>
                                        <?php 
                                            $aLogoType = isset($aLogo['type']) ? $aLogo['type'] : 'upload';

                                            $aSettings = array("text"=>"Text", "upload"=>"Upload an image"); 
                                        ?>
                                        <div class="form-control">
                                            <select name="theme_options[logo][type]" class="wo-logo-type">
                                                <?php 
                                                    foreach ($aSettings as $key => $value) :
                                                    $selected = $key == $aLogoType ? 'selected' : '';
                                                    ?>
                                                    <option value="<?php echo $key ?>" <?php echo $selected ?> ><?php echo $value ?></option>
                                                    <?php 
                                                    endforeach;
                                                ?>
                                            </select>
                                        </div>
                                        <br>
                                        <div class="form-control logo-text">
                                            <div class="controls">
                                                <input type="text" class="form-control" name="theme_options[logo][text]" value="<?php echo isset($aLogo['text']) ? stripslashes($aLogo['text']) : ''; ?>">
                                            </div>
                                        </div>

                                        <div class="form-control logo-text">
                                            <div class="controls">
                                                <input type="text" class="form-control color-picker" name="theme_options[logo][logo_color]" value="<?php echo isset($aLogo['logo_color']) ? stripslashes($aLogo['logo_color']) : '#fff'; ?>">
                                            </div>
                                        </div>

                                        <div class="form-group upload-logo">
                                            <?php $logoImage = isset($aLogo['upload']) && !empty($aLogo['upload']) ? $aLogo['upload'] : plugin_dir_url(__FILE__)  . 'assets/images/logo-default.png'; ?>
                                            <div class="image-wrap wrap-logo">
                                                <span><img src="<?php echo $logoImage; ?>" ></span>
                                            </div>
                                            <br>
                                            <a class="btn btn-white upload-img" data-insertlink=".wo-insert-link" data-append=".image-wrap">Get image</a>
                                            <input class="insertlink" type="hidden" value="<?php echo  $logoImage; ?>" name="theme_options[logo][upload]">
                                        </div>


                                    </div>
                                </div>
                                  <!-- Panel -->
                                <div class="panel">

                                    <div class="panel-heading">
                                        <div class="panel-title">
                                           Blog Options
                                        </div>
                                    </div>

                                    <div class="panel-body wo-flag">
                                        <div class="form-control">
                                            <div class="slider">
                                               <input type="checkbox" id="enable-sharingbox" name="theme_options[blog][sharingbox]" value="1" <?php echo  (isset($aBlog['sharingbox']) && !empty ($aBlog['sharingbox']) ) ? 'checked' : ''; ?>>
                                                <label for="enable-sharingbox">Display sharing box</label>
                                            </div>
                                        </div>
                                    </div>

                                </div>


                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div id="section" class="inner-tabs-panel">
                <div class="inner-content">
                    <div class="container-12-fluid">
                        <div class="container-12-row">
                            <div class="large-12">
                                <div class="wo-wrap-subtabs">
                                    <ul class="wo-subtabs">
                                        <li><a href="#header">Header</a></li>
                                        <li><a href="#ourservices">Our Services</a></li>
                                        <li><a href="#aboutus">About US</a></li>
                                        <li><a href="#ourteam">Our Team</a></li>
                                        <li><a href="#ourworks">Our Works</a></li>
                                        <li><a href="#ourclients">Our Clients</a></li>
                                        <li><a href="#contact">Contact</a></li>
                                    </ul>
                               
                                    <div class="wo-subtabs-content">    
                                        <?php 
                                            $aFiles = array("header.php", "ourwork.php", "services.php", "aboutus.php", "ourteam.php", "ourclients.php", "contact.php");

                                            foreach ($aFiles as $file)
                                            {
                                                include ( WO_ADMIN_PHP . $file );
                                            }
                                        ?>  
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div id="footer" class="inner-tabs-panel">
                <div class="inner-content">
                    <div class="container-12-fluid">
                        <div class="container-12-row">
                            <div class="large-12">
                                <div class="panel">
                                    
                                    <div class="panel-heading">
                                        <div class="panel-title">Footer</div>
                                    </div>

                                    <div class="panel-body wo-footer-socials-network">
                                       <h3>Social Networks</h3>

                                       <?php $aFooterSocial =  isset($aFooter['social']) ? $aFooter['social'] : array(); 
                                            $aFooterSocial = wp_parse_args($aFooterSocial, array( 'social_icon' => array('fa fa-refresh'), 'social_link' => array('#') ));

                                            foreach ($aFooterSocial['social_icon'] as $k  => $socialIcon) :
                                       ?>
                                       <div class="form-group item form-social fix-form wo-footer-socials">                       
                                            <div class="wrap-social">  
                                              <a class="icon thickbox available-panel" href="#TB_inline?width=600&height=550&inlineId=table-fa"><i class="<?php echo $socialIcon ?>"></i></a>
                                              <input type="hidden" name="theme_options[footer][social][social_icon][]" value="<?php echo $socialIcon ?>">
                                              <input type="text" name="theme_options[footer][social][social_link][]" value="<?php echo $aFooterSocial['social_link'][$k] ?>" placeholder="Link">
                                              <a class="remove-socials" data-class="remove"><i class="fa fa-times"></i></a> 
                                            </div>
                                       </div>

                                       
                                       <?php endforeach; ?>
                                       <div class="form-group add-toggle wo-add-social">
                                            <div class="controls">
                                                <input class="button wo-footer-addsocial" type="submit" value="Add">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="panel-body">
                                        <h3>Copyright</h3>
                                        <div class="form-group">
                                            <textarea class="form-control" name="theme_options[footer][copyright]"><?php echo isset($aFooter['copyright']) ? htmlspecialchars(stripslashes($aFooter['copyright'])) : ''; ?></textarea>
                                            <code class="help">Allow use all html tags</code>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div id="pagenotfound" class="inner-tabs-panel">
                <div class="inner-content">
                    <div class="container-12-fluid">
                        <div class="container-12-row">
                            <div class="large-12">
                                <div class="panel">
                                    <?php include( dirname(__FILE__) . '/assets/php/404.php' ); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <div id="main-2" class="main-tabs-panel">
        <div id="inner-tab1" class="inner-tab">
            
            <div class="menu-left">
                <ul class="tab-left">
                    <li><a href="#skins"><i class="fa fa-gears"></i>Skins</a></li>
                    <li><a href="#ordersection"><i class="fa fa-laptop"></i>Section Order</a></li>
                </ul>
            </div>

            <div id="skins" class="inner-tabs-panel">
                <div class="inner-content">
                    <div class="container-12-fluid">
                        <div class="container-12-row">
                            <div class="large-12">
                                <!-- Panel -->
                                <div class="panel">

                                    <div class="panel-heading">
                                        <div class="panel-title">
                                            Choose Skin
                                        </div>
                                    </div>

                                    <div class="panel-body">
                                        <h3>Color Schemes</h3>
                                        <div class="form-control">
                                                <?php 
                                                   $color_scheme = isset($aDesign['color_scheme']) && !empty($aDesign['color_scheme']) ? ltrim($aDesign['color_scheme'])  : "blue";
                                                    $aSettings = array("red", "green", "blue", "orange", "purple", "yellow");  
                                                    ?>
                                                    <ul class="skin-color qva-design">
                                                         <?php 
                                                            foreach ($aSettings as $v) :
                                                                $active = ($v == $color_scheme) ? " skin-active" : '';
                                                                ?>
                                                                <li class="<?php echo $v .  $active; ?>" data-key="<?php echo $v ?>"><a href="#"><i class="fa fa-check"></i></a></li>
                                                                <?php 
                                                            endforeach;
                                                        ?>
                                                    </ul>
                                                    <input class="hidden" name="theme_options[design][color_scheme]" value="<?php echo $color_scheme ?>">
                                        </div>
                                    </div>
                                    
                                </div><!-- END Panel -->
								
								<!-- Panel -->
                                <div class="panel">

                                    <div class="panel-heading">
                                        <div class="panel-title">
                                            Blog design
                                        </div>
                                    </div>

                                    <div class="panel-body">
                                        <h3>Blog type</h3>
                                        <div class="form-control">
                                            <ul class="sidebar-op">
                                                <?php 
                                                    $csidebar = isset($aDesign['choosidebar']) && !empty($aDesign['choosidebar']) ? $aDesign['choosidebar'] : 'r-sidebar';
                                                    $aSidebar = array("r-sidebar" => "Right sidebar", "l-sidebar"=>"Left sidebar", "no-sidebar"=>"No sidebar");

                                                    foreach ($aSidebar as $sidebar => $name) :
                                                        $active = $sidebar == $csidebar ? 'sidebar-active' :'';
                                                ?>
                                                <li>
                                                    <a href="#" class="<?php echo $active ?> choosidebar" data-sidebar="<?php echo $sidebar ?>"><img src="<?php echo WO_ADMIN_IMG , $sidebar , '.png'; ?>" alt=""></a>
                                                    <span><?php echo $name ?></span>
                                                </li>
                                                    <?php endforeach; ?>
                                                <input class="hidden sidebar-value" name="theme_options[design][choosidebar]" value="<?php echo $csidebar ?>">
                                            </ul>

                                        </div>
                                    </div>
                                    
                                </div><!-- END Panel -->
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div id="ordersection" class="inner-tabs-panel">
                <div class="inner-content">
                    <div class="container-12-fluid">
                        <div class="container-12-row">
                            <div class="large-12">
                                <!-- Panel -->
                                <div class="panel">

                                    <div class="panel-heading">
                                        <div class="panel-title">
                                             Section
                                        </div>
                                    </div>

                                    <div class="panel-body">
                                        <h3>Section Order</h3>
                                        <div class="form-control">
                                        
                                                <ul id="sortable" class="wo-sortable">
                                                    <?php
                                                        $aSection = isset($aDesign['section_order']) && !empty($aDesign['section_order']) ? explode(",", $aDesign['section_order']):  array("ourservices", "aboutus", "ourteam", "ourwork", "ourclients", "contact");
                                                        $aName  = array("ourservices"=>"Our Services", "aboutus"=>"About Us", "ourteam"=>"Our Team", "ourwork"=>"Our Works", "ourclients"=>"  Our Clients", "contact"=>"Contact");
                                                        $allHidden = true;
                                                        foreach ($aSection as $v)
                                                        {   
                                                            $v = ltrim($v);
                                                            $allHidden  = isset($aOptions['theme_options'][$v]['enable']) ? false : true;
                                                            ?>
                                                            <li  class="<?php if (!isset($aOptions['theme_options'][$v]['enable'])) echo 'hidden'; ?>" data-name="<?php echo $v ?>"><span class="ui-icon ui-icon-arrowthick"></span><?php echo $aName[$v] ?></li>
                                                            <?php 
                                                        }
                                                        if($allHidden) echo "Currently, All sections are deactived";
                                                     ?>
                                                    <input type="hidden" class="section-order" name="theme_options[design][section_order]" value="<?php echo  isset($aDesign['section_order']) && !empty($aDesign['section_order']) ? $aDesign['section_order'] : 'ourservices, aboutus, ourteam, ourwork, ourclients, contact' ?>">
                                                </ul>
                                                <a href="#" class="section-order-reset btn btn-danger">Reset</a>
                                            </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <div id="main-3" class="main-tabs-panel">
        <div id="inner-tab1" class="inner-tab">

            <div class="menu-left">
                <ul class="tab-left">
                    <li><a href="#imex"><i class="fa fa-cloud-upload"></i>Import/Export</a></li>
                    <!-- <li><a href="#parallax">Parallax</a></li> -->
                </ul>   
            </div>


            <div id="imex" class="inner-tabs-panel">
                <div class="inner-content">
                    <div class="container-12-fluid">
                        <div class="container-12-row">
                            <div class="large-12">
                                <!-- Panel -->
                                <div class="panel">
                                       
                                        <div class="panel-body">
                                            <h3>Import your settings</h3>
                                            <div class="form-group">
                                                <div class="controls">
                                                    <?php 
                                                        // if ( isset($_POST['data-import']) && !isset($_POST['wo-save-options'])  ) 
                                                        // {
                                                        //     if ( !empty($_POST['data-import']) ) :
                                                        //     // $content = stripslashes($_POST['data-import']);
                                                        //     $content = base64_decode(unserialize($content));
                                                        //     update_option("wo_save_theme_options", $content);
                                                             // <script type="text/javascript">
                                                            
                                                           
                                                            // var elem = document.getElementById("qva-success");
                                                            //     elem.style.display = "block";
                                                            // </script>
                                                            
                                                            // else : 
                                                            
                                                            // <script type="text/javascript">
                                                            // var $elem;
                                                            // $elem = document.getElementById("qva-empty-data");
                                                            // $elem.style.display = "block";
                                                            // </script>
                                                            
                                                            // endif;
                                                           
                                                            // <script type="text/javascript">
                                                            // setTimeout( function(){
                                                            //     window.location.href=window.location.href;
                                                            // }, 2000 );
                                                            // setTimeout(function(){
                                                            //     jQuery(".alert").hide('slow');
                                                            // }, 4000);
                                                            
                                                            // </script>
                                                            // <?php 
                                                            // unset($_POST['data-import']);
                                                        // }
                                                    ?>
                                                    <textarea class="form-control data-import" name="data-import"></textarea>
                                                    <br>
                                                    <input type="submit" name="import-theme-options" class="btn btn-red import-theme-options red" value="Import">
                                                </div>
                                            </div>
                                        </div>

                                        <div class="panel-body">
                                            <h3>Export</h3>
                                            <div class="form-group">
                                                <?php 
                                                    $exOptions = $aOptions;
                                                    // unset($exOptions['init-save-options']);
                                                    // unset($exOptions['_wp_http_referer']);
                                                   
                                                    $export = serialize($exOptions); 
                                                ?>
                                                <textarea class="form-control"><?php echo $export; ?></textarea>
                                                <input type="hidden" name="_wo_nonce" value="<?php echo wp_create_nonce("qva-secure") ?>">
                                               <?php  wp_referer_field(); ?>
                                               <br>
                                               <input type="submit" name="export-theme-options" class="btn btn-red export-theme-options red" value="Save to file">
                                            </div>
                                        </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!--/#imex -->
    </div>

   
</div>
<div class="button-footer">
    <div class="wo-wrap-button container-12-fluid">
        
     
            <div class="form-group">
                <button type="submit" name="wo-save-options" value="Save" class="btn btn-red">Save</button>
                <!-- <button type="submit" class="btn btn-black">Reset</button> -->
            </div>

        
        <!-- <input class="button button-primary" type="submit" name="wo-save-options" value="Save">
        <input class="button" type="submit" name="wo-reset-options" value="Reset"> -->
    </div>
</div>

</form><!-- form -->